package pl.jtb.ctl.tabory.ui.editors;

import org.apache.log4j.Logger;
import org.eclipse.jface.action.Action;
import org.eclipse.ui.IWorkbenchWindow;

public class OpenViewTripEditorAction extends Action {

    private final Logger log = Logger.getLogger(OpenViewEditorAction.class);

    private final IWorkbenchWindow window;
    private final String viewId;

    public OpenViewTripEditorAction(final IWorkbenchWindow window, final String label, final String viewId) {
        this.window = window;
        this.viewId = viewId;
        this.setText(label);
        this.setId(viewId);
    }

    @Override
    public void run() {
        log.debug("Opening view: " + viewId);
        if (this.window != null) {
            try {
                this.window.getActivePage().showView(this.viewId);
            } catch (final Exception e) {
                this.log.error(e.getMessage(), e);
            }
        }
    }
}
